﻿using System;
using System.ServiceModel;
using System.Web;
using System.Web.Caching;
using ZFine.Web.WebLinkWS;

namespace ZFine.Web.Services
{

    public struct SMSTemp
    {
             public const string Temp1     = "您好，欢迎使用中小学转学报名系统，您的手机验证码是：{0}，请妥善保管，请勿向他人泄露";          
             public const string Temp2     = "您所提交的信息有错误或不完整，请您及时登录系统进行修改";
             public const string Temp3     = "您所提交的入学信息已经通过初审，将进入复审流程，敬请等待";
             public const string Temp4     = "您的孩子的转学申请已经通过，转去学校是{0}，年级{1}，请于{2}带入学资料原件到学校报到";
    }
  public   class SMSServices
    {
         
        const string CorpID = "JNJS004028";
        const string Pwd = "zm0513@";








        public static int Send(string mobile,string content)
        {
            LinkWSSoapClient sms = new LinkWSSoapClient(new BasicHttpBinding(), new EndpointAddress("http://sdk2.028lk.com/sdk2/linkws.asmx"));
           return sms.BatchSend(CorpID, Pwd, mobile, content, null, null);          
        }

        public static bool SendVerifyCode(string mobile,string template,string code)
        {
            string message = string.Format(template, code);
            int result = Send(mobile, message);
            if (result > 0)
            {
           
                HttpRuntime.Cache.Insert("verifycode-" + mobile, code, null, DateTime.UtcNow.AddMinutes(5),Cache.NoSlidingExpiration);
                return true;
            }
            return false;
        }

        public static bool CheckVerifyCode(string mobile, string code)
        {
            object  value = HttpRuntime.Cache.Get("verifycode-" + mobile);
            return value != null && value.ToString() == code;
        }
    }
}
